package com.ydh.company.controller;

import com.ydh.company.dto.ResponseData;
import com.ydh.company.dto.ResultData;
import com.ydh.company.pojo.Condition;
import com.ydh.company.pojo.OrderDetails;
import com.ydh.company.pojo.OrderMain;
import com.ydh.company.service.OrderService;
import com.ydh.company.utils.UUIDUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.sql.Timestamp;

/**
 * @Auther 周晓东
 * @Date 2020/4/30
 */

/**
 * 这部分是供货端的订单模块功能
 */
@RestController
@RequestMapping("/order")
@Api(value = "供货端订单模块接口",tags = "订货单、退货单接口API")
public class OrderController {

    @Autowired
    private UUIDUtil uuidUtil;
    @Autowired
    private OrderService orderService;
    /*************************订单详情表,用于订货单、退货单调用*******************************/
    //接口，查询订单中商品详情信息，用于商品详情表调用
    //有订单号、客户信息、购物车中商品的信息、仓库信息
    //通过购物车Redis调取购物车中商品的ID、客户ID、订单ID、仓库信息等信息
    /**
     * 订单详情查询接口
     * @param orderMain
     * @return
     */
    @PostMapping("/order_details")
    @ApiOperation(value = "订货单--订单详情接口",notes = "订货单详情",httpMethod = "POST",response = ResponseData.class)
    public ResultData order_details(
            @RequestBody
            @ApiParam(name = "orderMain",
            value = "传入订单主表id",
            required = true) OrderMain orderMain){
        OrderDetails orderDetails = new OrderDetails();
        orderDetails.setGoodsId("fdsafdsafdsaf//商品id");
        orderDetails.setNotes("商品备注：买买买");
        orderDetails.setRepositoryId("仓库id");
        orderDetails.setClientId("客户信息id");
        orderDetails.setGoodsNum(100);
        orderDetails.setDeliveryTime(Timestamp.valueOf("2020-03-04 12:56:43"));

        return ResponseData.success("订单详情查询",orderDetails);
    }

    /**************************订货单接口**************************/
    /**
     * 查询订货单
     * 进入订单管理的订货单处显示的订货单
     * 实体类:order_main
     * @return
     */
    @PostMapping("/queryOrder")
    @ApiOperation(value = "订货单--查询订货单接口",notes = "查询订货单信息",httpMethod = "POST",response = ResponseData.class)
    public ResultData queryOrder(
            @RequestBody
            @ApiParam(name = "condition",
            value = "传入分页查询订货单的页数、显示条数",
            required = true) Condition condition){

        condition.getCurrentPage();
        condition.getPerSize();

        OrderMain orderMain = new OrderMain();
        orderMain.setOrderMainId("fsdfljskldfds//主表id");
        orderMain.setOrderNumber("fkjlsdjfkldsl//订单号");
        orderMain.setClientId("fdfkldsjflsd//客户id");
        orderMain.setOrderMainPrice(100.0);
        orderMain.setOut(0L);
        orderMain.setReceipt(0L);
        orderMain.setOrderAuditStatus(0L);
        orderMain.setCollectStatus(0L);
        orderMain.setOutStatus(0L);
        orderMain.setOrderStatus(0L);
        orderMain.setOrderTime(Timestamp.valueOf("2020-03-04 02:34:45"));

        return ResponseData.success("查询订货单成功",orderMain);
    }

    /**
     * 增加订货单-->在生成的订货单中增加商品-->保存-->增加了订货单
     *
     * 订货单处的增加订单
     *
     * 页面功能实现：
     * 调用商品列表查询，查询商品信息
     * 前端将加入购物车的商品详情放入页面
     *
     * 将要添加的商品ID,数量记录，并将增加商品设计放入Redis中！
     *    通过页面可修改Redis(购物车)中商品的数量,或删除Redis(购物车)中的商品
     *      生成订单号
     * 调用客户信息显示到页面
     *
     * 传入(关联)：经销商ID、(商品ID、商品数量)-->redis、备注
     *           client_id、goods
     * 实体类:OrderDetails
     * @return
     */
    @PostMapping("/addOrder")
    @ApiOperation(value = "订货单--增加订货单接口",notes = "增加订货单",httpMethod = "POST",response = ResponseData.class)
    public ResultData addOrder(
            @RequestBody
            @ApiParam(name = "orderDetaisls",
            value = "传入增加订货单的相关字段",
            required = true) OrderDetails orderDetails){
        return ResponseData.success("增加订货单成功",null);
    }

//      订单审核接口
//    经销商、商品信息、仓库、订单信息(订单号)、订单号
//    order_main(包含审核状态)
    /**
     * 订单审核接口：
     * 1、订单详情使用实体类order_details
     * 2、审核成功，使用实体类order_main改变审核状态
     * 3、若审核失败。。。
     * 订单详情表使用接口查询详情，审核成功使用接口改变订单审核状态
     * @param orderMain
     * @return
     */
    @PostMapping("/order_examine")
    @ApiOperation(value = "订货单--改变订单审核状态接口",notes = "审核订单",httpMethod = "POST",response = ResponseData.class)
    public ResultData order_examine(
            @RequestBody
            @ApiParam(name = "orderMain",
            value = "传入想要审核订单的订单号",
            required = true) OrderMain orderMain){
        return ResponseData.success("订单审核成功",null);
    }

    //订单财务审核
    /**
     * 订单的财务审核，通过订单号，改变订单主表订单状态
     * @param orderMain
     * @return
     */
    @PostMapping("/audit_financial")
    @ApiOperation(value = "订货单--改变订单的财务审核状态接口",notes = "财务审核",httpMethod = "POST",response = ResponseData.class)
    public ResultData audit_financial(
            @RequestBody
            @ApiParam(name = "orderMain",
            value = "传入想要财务审核的订单号",
            required = true) OrderMain orderMain){
        return ResponseData.success("财务审核成功",null);
    }

//    出库审核

    /**
     * 订单出库审核
     * -->后期完善:若通过库存数量减去订单商品数量不足，则返回出库失败
     * @param orderMain
     * @return
     */
    @PostMapping("/audit_outbound")
    @ApiOperation(value = "订货单--改变订单的出库审核状态接口",notes = "出库审核",httpMethod = "POST",response = ResponseData.class)
    public ResultData audit_outbound(
            @RequestBody
            @ApiParam(name = "orderMain",
            value = "传入想要出库审核的订单号",
            required = true) OrderMain orderMain){
        return ResponseData.success("出库审核成功",null);
    }

    /**
     * 订单发货接口
     * 暂时不搞物流信息
     * @return
     */
    @PostMapping("/deliver_goods")
    @ApiOperation(value = "订货单--改变订单的发货状态接口",notes = "发货接口",httpMethod = "POST",response = ResponseData.class)
    public ResultData deliver_goods(
            @RequestBody
            @ApiParam(name = "orderMain",
            value = "传入想要发货的订单号",
            required = true) OrderMain orderMain){
        return ResponseData.success("发货审核成功",null);
    }


    /***************************退货单接口****************************/
    /**
     * 退货单查询，分页查询,传入分页信息
     * @return
     */
    @PostMapping("/returned_order")
    @ApiOperation(value = "退货单--查询退货单接口",notes = "查询退货单",httpMethod = "POST",response = ResponseData.class)
    public ResultData returned_order(
            @RequestBody
            @ApiParam(name = "condition",
            value = "传入查询退货单分页的页码和显示条数",
            required = true) Condition condition){
        OrderMain orderMain = new OrderMain();
        orderMain.setOrderMainId("fsdfljskldfds//主表id");
        orderMain.setOrderNumber("fkjlsdjfkldsl//订单号");
        orderMain.setClientId("fdfkldsjflsd//客户id");
        orderMain.setOrderMainPrice(100.0);
        orderMain.setOut(0L);
        orderMain.setReceipt(0L);
        orderMain.setOrderAuditStatus(0L);
        orderMain.setCollectStatus(0L);
        orderMain.setOutStatus(0L);
        orderMain.setOrderStatus(0L);
        orderMain.setOrderTime(Timestamp.valueOf("2020-01-21 23:43:54"));
        return ResponseData.success("退货订单查询",orderMain);
    }

    //ordermain退单审核
    /**
     * 退货审核
     * @param orderMain
     * @return
     */
    @PostMapping("/return_goods")
    @ApiOperation(value = "退货单--退货审核接口",notes = "退货审核",httpMethod = "POST",response = ResponseData.class)
    public ResultData return_goods(
            @RequestBody
            @ApiParam(name = "orderMain",
            value = "传入想要退货审核的退货单单号",
            required = true) OrderMain orderMain){
        return ResponseData.success("退单审核成功",null);
    }
    
    //退款确认
    /**
     * 退款审核
     * @return
     */
    @PostMapping("/return_money")
    @ApiOperation(value = "退货单--退款审核接口",notes = "退款审核",httpMethod = "POST",response = ResponseData.class)
    public ResultData return_money(
            @RequestBody
            @ApiParam(name = "orderMain",
            value = "传入想要退款审核的退货单号",
            required = true) OrderMain orderMain){
        return ResponseData.success("退款确认",null);
    }

    //收款确认--订货端确认
}
